public class RoutAarry {

    //二分法查找旋转数组的[note]
    public int Search(int[] num, int target) {
        if (num == null || num.length == 0) {
            return -1;
        }
        //索引 start end mid  45623
        int start = 0;
        int end = num.length - 1;
        int mid;
        while (start < end) {
            mid = start + (end - start) / 2;
            if (target == num[mid]) {
                return mid;
            }
            if (num[start] < num[mid]) {
                if (target >= num[start] && target <= num[mid]) {
                    end = mid;
                } else {
                    start = mid;
                }
            } else {
                /*if (num[target]>num[mid]) 5 2*/
                if (target >= num[mid] && target <= num[end]) {
                    start = mid;
                } else {
                    end = mid;
                }
            }
        }
        if (num[start] == target) {
            return start;
        }
        if (num[end] == target) {
            return end;
        }
        return -1;
    }
}
